package com.lc.controller;

import com.cnpc.framework.base.entity.BaseResponse;
import com.lc.entity.Msg;
import com.lc.service.MsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 下雨不带伞 on 2020/9/7.
 */
@Controller
@RequestMapping("/app/msg")
public class MsgController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private MsgService msgService;

    @ResponseBody
    @RequestMapping("editMsg")
    public BaseResponse editMsg(Msg msg) {
        BaseResponse response;
        try {
            response = msgService.editMsg(msg);

        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(2);
            response.setMessage("系统繁忙");
        }
        return response;
    }

    @ResponseBody
    @RequestMapping("getMsgList")
    public BaseResponse getMsgList(
            String userId, String keyword,String status, String startTime, String endTime,
            @RequestParam(value = "pageNum", required = false) Integer pageNum,
            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        BaseResponse response;
        try {

            response = msgService.getMsgList(userId, keyword,status, startTime, endTime, pageNum, pageSize);


        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(2);
            response.setMessage("系统繁忙");
        }
        return response;
    }

    @ResponseBody
    @RequestMapping("getAppMsgList")
    public BaseResponse getAppMsgList(
            @RequestParam("userId")String userId,
            @RequestParam(value = "keyword", required = false)String keyword,
            @RequestParam(value = "status", required = false)String status,
            @RequestParam(value = "startTime", required = false) String startTime,
            @RequestParam(value = "endTime", required = false) String endTime,
            @RequestParam(value = "pageNum", required = false) Integer pageNum,
            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        BaseResponse response;
        try {

            response = msgService.getAppMsgList(userId, keyword,status, startTime, endTime, pageNum, pageSize);


        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(2);
            response.setMessage("系统繁忙");
        }
        return response;
    }

    @ResponseBody
    @RequestMapping("deleteMsg")
    public BaseResponse deleteMsg(
            @RequestParam("msgId") String msgId) {
        BaseResponse response;
        try {

            response = msgService.deleteMsg(msgId);


        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(2);
            response.setMessage("系统繁忙");
        }
        return response;
    }

    @ResponseBody
    @RequestMapping("getMsg")
    public BaseResponse getMsg(
            @RequestParam("msgId") Integer msgId,
            @RequestParam("userId") String userId) {
        BaseResponse response;
        try {

            response = msgService.updateAndGetMsg(msgId,userId);


        } catch (Exception ex) {
            logger.error(ex.getMessage());
            ex.printStackTrace();
            response = new BaseResponse();
            response.setStatus(2);
            response.setMessage("系统繁忙");
        }
        return response;
    }



}
